<?php


namespace App\Http\Controllers\Admin;
use App\Lib\UploadLib;
use App\Models\Config;
use Dingo\Api\Http\Request;

class ConfigController extends BaseController
{

    public function site(Request $request) {
        $info = Config::getSiteVal();
        $info['logo_url'] = Config::getLogoUrl($info['logo']);
        return $this->success($info);
    }

    /**
     * 修改
     * @param Request $request
     * @return mixed
     * @throws \Illuminate\Validation\ValidationException
     */
    public function update(Request $request) {
        $this->validate($request, [
            'logo' => 'required',
            'email' => 'required',
            'address' => 'required',
            'record' => 'required',
            'about_us' => 'required',
//            'desc_top' => 'required',
//            'desc_footer' => 'required',
//            'desc_recommend' => 'required'
        ]);
        $input = $request->input();

        if ($request->hasFile('logo')) {
            $input['logo'] = UploadLib::handle($request->file('logo'), 'upload_logo');
        }
        $model = Config::where('key',Config::SITE_KEY )->first();
        $model->value = json_encode($input, JSON_UNESCAPED_UNICODE);
        $model->save();
        return $this->success([]);
    }

    public function commissionedRole() {
        $list = Config::where('key', Config::COMMISSIONED_ROLE_TYPE)->select("id", "value")->get();
        return $this->success($list);
    }



}

